#include "do_sys.h"
#include "cmd.h"

#ifdef ENV_SUPPORT
#include "var.h"
#endif

int QuitFlag = 0;

int do_ver(int argc, char **argv)
{
#ifdef ENV_SUPPORT
	Var *pvar = find_var("DIAGVER");
	if (pvar->var_value)
		printf("version %s\n", pvar->var_value);
	else
		puts("version 1.0");
#else
	puts("version 1.0");
#endif
	return 0;
}

void man_ver(void)
{
	printf("Usage:\n\tver\n");
}

int do_help(int argc, char **argv)
{
	if(argc == 2) {
		return show_manual(argv[1]);
	} else {
		show_cmds();
	}
	return 0;
}

void man_help(void)
{
	printf("Usage:\n\thelp\n");
}


int do_shell(int argc, char **argv)
{
	char cmdline[CMD_BUF_SIZ] = {0};
	int i = 1;	/* 'shell' takes the argv[0] */

	while (i < argc) {
		strcat(cmdline, argv[i++]);
		strcat(cmdline, " ");
	}

	if (argc < 2) {
		printf("Missing parameter!\n");
		return 1;
	} else {
		system(cmdline);
		return 0;
	}

}

void man_shell(void)
{
	printf("Usage:\n\tshell [cmd] [arguments...]\n");
}

int do_quit(int argc, char **argv)
{
	QuitFlag = 1;
	printf("Quiting...\n");
	return 0;
}

void man_quit(void)
{
	printf("Usage:\n\tquit\n");
}

